package com.example.as_sum.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.as_sum.R;

public class MatrixTextActivity extends BaseActivity {
    private static final String TAG = "MatrixTextActivity";
    private ImageView mImg;
    private Bitmap mBitmap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTitle("Matrix测试");
    }

    @Override
    public int getContentId() {
        return R.layout.activity_matrix_text;
    }
    public void showNow(View view){
        mImg.setImageBitmap(mBitmap);
    }
    public void showSuoFang(View view){
        Matrix matrix=new Matrix();
//        matrix.postScale(0.5f,1f);
        //上下颠倒
        matrix.postScale(1,-1);
        matrix.postTranslate(10,10);
        Bitmap bitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
        mImg.setImageBitmap(bitmap);
    }
    public void showXuanZhuan(View view){
        Matrix matrix=new Matrix();
        //围绕默认点(0,0)，正数将顺时针旋转图像，而负数将逆时针旋转图像，其中默认点是图像的左上角
        //matrix.postRotate(90);
        //也可以使用旋转的角度及围绕的旋转点作为参数调用setRotate方法。选择图像的中心点作为旋转点
        matrix.postTranslate(20,20);
        matrix.postRotate(30,mBitmap.getWidth()/2,mBitmap.getHeight()/2);
        Bitmap bitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
        mImg.setImageBitmap(bitmap);
    }
    public void showPingYi(View view){
        Matrix matrix=new Matrix();
        matrix.postRotate(60);
        matrix.postTranslate(100,0);
       // Bitmap bitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
        mImg.setImageMatrix(matrix);
        //mImg.setImageBitmap(bitmap);
    }
    public void showXieQie(View view){
        Matrix matrix=new Matrix();
        matrix.postSkew(0,0.5f);
        Bitmap bitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
        mImg.setImageBitmap(bitmap);
    }
    public void showSC(View view){
        Matrix matrix=new Matrix();
        matrix.postSkew(0,0.5f);
        Bitmap bitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
        mImg.setImageBitmap(bitmap);
    }
    @Override
    public void initView() {
        mImg = (ImageView) this.findViewById(R.id.img);
        mBitmap= BitmapFactory.decodeResource(getResources(),R.drawable.bk);
    }

    @Override
    public void addListener() {

    }

    @Override
    public void loadData() {

    }

    @Override
    public Handler getHandler() {
        return null;
    }
}
